package controllers

import (
	"github.com/astaxie/beego"
)

type LoginController struct {
	beego.Controller
}

func (c *LoginController) Get() {
	c.TplName = "login.tpl"
}

// 处理登录
func (c *LoginController) HandleLogin() {
	username, password := c.GetString("username"), c.GetString("password")
	if username == "admin" && password == "123456" {
		c.SetSession("username", username)
		c.Data["json"] = map[string]interface{}{"status": true, "msg": "登录成功~"}
	} else {
		c.Data["json"] = map[string]interface{}{"status": false, "msg": "登录失败~"}
	}
	c.ServeJSON()
}

// 退出登录
func (c *LoginController) Logout() {
	c.DelSession("username")
	// c.DestroySession()
	c.Ctx.Redirect(302, "/login")
}
